package com.jy.unkown;

import com.jy.unkown.entity.UnkownAdBean;
import com.jy.unkown.view.UnkowVideoView;
import com.jy.unkown.view.UnkownADView;
import com.jy.utils.utils.LogUtils;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class UnkownVideoPoint implements PlayProgressListener {

    List<UnkownAdBean.TracksDTO> tracks;
    UnkowVideoView unkowVideoView;
    UnkownADView unkownADView;
    HashSet<Integer> hashSet = new HashSet<>();

    public UnkownVideoPoint(UnkownADView unkownADView, UnkowVideoView unkowVideoView, List<UnkownAdBean.TracksDTO> list) {
        this.unkowVideoView = unkowVideoView;
        this.unkownADView = unkownADView;
        this.tracks = list;
    }


    public void init() {
        unkowVideoView.setPlayProgressListener(this::play);
    }

    /**
     * 播放进度
     * 0—播放进度 0%(开始播放)
     * 1—播放进度 25%
     * 2—播放进度 50%
     * 3—播放进度 75%
     * 4—播放进度 100%(播放结束)
     * 101-视频全屏播放
     * 102-退出全屏播放
     * 103-静音播放
     * 104-关闭静音
     * 105-播放视频时有屏幕上滑操作
     * 106-播放视频时有屏幕下滑操作
     * 107-视频暂停播放
     * 108-视频暂停后继续播放
     * 109-播放结束后重新播放
     *
     * @param curr
     * @param total
     */

    boolean isEnd;
    boolean isPosted = false;

    @Override
    public void play(int curr, int total, int progress) {
        if (!isEnd) {
            isEnd = progress == 100;
        }


        if (tracks != null) {
            for (int i = 0; i < tracks.size(); i++) {
                UnkownAdBean.TracksDTO tracksDTO = tracks.get(i);
                if (tracksDTO != null) {
                    if (progress == 0 && tracksDTO.type == 0) {
                        unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放进度0", tracksDTO.urls);
                    } else if (progress == 25 && tracksDTO.type == 1) {
                        unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放进度25 ", tracksDTO.urls);
                    } else if (progress == 50 && tracksDTO.type == 2) {
                        unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放进度50 ", tracksDTO.urls);

                    } else if (progress == 75 && tracksDTO.type == 3) {
                        unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放进度75 ", tracksDTO.urls);

                    } else if (progress == 100 && tracksDTO.type == 4) {
                        unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放进度100 ", tracksDTO.urls);
                    }
                    if (isEnd && !isPosted && progress > 0) {
                        isPosted = true;
                        if (tracksDTO.type == 109) {
                            unkownADView.pointPost(UnkownADView.PLAY_VIDEO,"播放结束后重新播放 ", tracksDTO.urls);
                        }
                    }
                }
            }
        }
    }


}
